<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <meta http-equiv="X-UA-Compatible" content="ie=edge">

    <title>Document</title>

</head>

<body>

    <script>

        class rect{

            constructor(w,h){

                this.w=w;

                this.h=h;

                this.cname="长方形";

            }

            //构造器

            //方法

            mj(){

                console.log("mj="+(this.w*this.h));

            }

            zc(){

                console.log("zc="+(this.w*2+this.h*2));

            }

        }

        var r1=new rect(333,66);

        var r2=new rect(55,10);

        r1.mj();

        r2.zc();

 

        class square extends rect{

            constructor(w){

                super(w,w);//super一定要在构造函数里执行

                //必须执行super后才能调用this

                this.cname="正方形";

            }

        }

        let s1=new square(19);

        let s2=new square(20);

        s1.mj();

        s2.zc();

        console.log(rect.prototype);

        console.log(s1.__proto__==square.prototype);

        console.log(s1.__proto__.__proto__==rect.prototype);

        console.log(r1.hasOwnProperty("w"));//是否有w这个属性

        console.log(r1.hasOwnProperty("mj"));

        console.log(rect.prototype.hasOwnProperty("mj"));

        console.log(rect.prototype);

        rect.prototype.say=function(){

            console.log(this.cname);

        }

        r1.say();

        s1.say();

    </script>

</body>

</html>